home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #14 / Monster Media No. 14 (April 1996) (Monster Media, Inc.).ISO / prog_d / oleauttr.zip / OLEAUTO.INT < prev    next >
Text File  |  1996-01-04  |  10KB  |  205 lines

  1. {
  2. // OLEAUTO.INT (C) 1995 W. Raike
  3. //              ALL RIGHTS RESERVED.
  4. //   NOTICE:    This file consists of trade secrets that are the property
  5. //              of William Raike.  The contents may not be used or disclosed
  6. //              without express written permission of the owner.
  7.  
  8.         NOTE: The information in this file is for information only and
  9.         is subject to change.
  10. }
  11.  
  12. {
  13. ****************************************************************
  14. Here are the most important sections of the public interface for
  15. the Delphi classes contained in the module OLEAUTO.DCU :
  16. ****************************************************************
  17. }
  18. interface
  19.  
  20. uses
  21.     Classes, SysUtils;
  22.  
  23. const
  24.     MAXARGS = 64;   { Max. no. of arguments to a method. }
  25.  
  26. type
  27.   DWORD = longint;
  28.   ULONG = DWORD;
  29.   HRESULT = Pointer;
  30.   ppV = ^Pointer;       { Pointer to pointer }
  31.   pPChar = ^PChar;      { Pointer to PChar }
  32.   pBYTE = ^Byte;        { Pointer to Byte }
  33.   pInt = ^Integer;      { Pointer to Integer }
  34.   pWORD = ^WORD;        { Pointer to WORD }
  35.   pDWORD = ^DWORD;      { Pointer to DWORD }
  36.   pSingle = ^Single;    { Pointer to Single }
  37.   pDouble = ^Double;    { Pointer to Double }
  38.   ODATE = Double;
  39.   pODATE = ^ODATE;
  40.   VARIANT_BOOL = Integer;
  41.   pVARIANT_BOOL = ^VARIANT_BOOL;
  42.   CY = record       { helper structure for currency }
  43.     Lo : DWORD;
  44.     Hi : DWORD;
  45.   end;
  46.   pCY = ^CY;
  47.   S_OK = HRESULT(nil);
  48.  
  49.   { OLE error codes - defined in SCODE.H - Values for OleAutoErrCode property.}
  50.   E_UNEXPECTED = HRESULT($8002FFFF); {relatively catastrophic failure}
  51.   E_NOTIMPL = HRESULT($80020001); {not implemented}
  52.   E_OUTOFMEMORY = HRESULT($80020002); {ran out of memory}
  53.   E_INVALIDARG = HRESULT($80020003); {one or more args are invalid}
  54.   E_NOINTERFACE = HRESULT($80020004); {no such interface supported}
  55.     { The following OleAutoErrCode usually results when the number or types
  56.       of arguments passed to a method/property call are not correct. }
  57.   E_POINTER = HRESULT($80020005); {invalid pointer}
  58.     { The following OleAutoErrCode usually results when the name
  59.       or type specified for CallOleProc or CallOleFunction is not correct. }
  60.   E_HANDLE = HRESULT($80020006); {invalid handle}
  61.   E_ABORT = HRESULT($80020007); {operation aborted}
  62.   E_FAIL = HRESULT($80020008); {unspecified error}
  63.   E_ACCESSDENIED = HRESULT($80020009); {general access denied error}
  64.  
  65. { Exception classes specific to TOleAutomationClient component: }
  66. type
  67.     EOleAutoNoCreate = class(Exception);
  68.     EOleAutoOutOfMemory = class(EOutOfMemory);
  69.     EOleAutoInvokeFailure = class(Exception);
  70.  
  71. { Public non-member functions. }
  72. procedure OleEnable; { Called by TOleAutomationClient component constructor }
  73. procedure OleDisable; { Called by TOleAutomationClient component destructor }
  74.  
  75. { Parent class from which to derive a "mirror" class that reflects the
  76.   properties/methods of the OLE Automation server you want to control. }
  77. type
  78.   TOleObject = class
  79.   protected
  80.     function GetPDisp : pIDisp; { Not normally used in derived classes. }
  81.     function GetRefCount : Integer; { Not normally used in derived classes. }
  82.         { Call the following function after a call to any of the other
  83.           member functions in this class to determine whether an error
  84.           occurred.  It returns True if an error occurred, False otherwise. }
  85.     function GetOleAutoFailFlag : Boolean;
  86.  
  87.         { See descriptions below to see how to use the following functions. }
  88.     procedure SetOleMethodArg(sParamType : String; var ActualParam); virtual;
  89.     procedure CallOleFunction(sMethodName : String; sReturnType : String; var Retval); virtual;
  90.     procedure CallOleProc(sMethodName : String); virtual;
  91.     procedure SetOleProperty(sPropertyName : String; sPropertyType : String; var PropVal); virtual;
  92.     procedure GetOleProperty(sPropertyName : String; sPropertyType : String; var RetVal); virtual;
  93.  
  94.     { The following properties contain error status information
  95.       pertaining to the most recent OLE method call and/or property access.}
  96.     property OleAutoFailFlag : Boolean;
  97.     { See the above OLE error code definitions for the possible values of
  98.       the following property.  E.g., S_OK, E_HANDLE, etc. }
  99.     property OleAutoErrCode : HRESULT;
  100.  
  101.   public
  102.     { Create when a pdisp is already available (i.e., for a nested object. }
  103.     constructor ConnectInterface(pdisp : PInterface); virtual;
  104.     { Create from scratch using an in-process server (.DLL server).  }
  105.     constructor CreateInProcessObject(prgid : String); virtual;
  106.     { Create from scratch using a local server (.EXE server),
  107.       or, if that fails, an in-process (16-bit DLL) server. }
  108.     constructor CreateObject(prgid : String); virtual;
  109.     { Get access to an already-running instance of an OLE auto server. }
  110.     constructor GetObject(prgid : String); virtual;
  111.     destructor Release ; virtual;
  112.   end;
  113.  
  114. { This module calls external functions in DLLs that should be in
  115.    \WINDOWS\SYSTEM.  The required DLLs are OLE2.DLL and OLE2DISP.DLL,
  116.    and functions in these (Microsoft-supplied) DLLs may in turn call
  117.    functions in others such as COMPOBJ.DLL, MSOLE2.DLL, OLE2REG.DLL,
  118.    OLE2NLS.DLL and possibly others. }
  119.  
  120. {
  121. ****************************************************************
  122. Here are explanations of the parameters to the class methods:
  123. ****************************************************************
  124. }
  125.  
  126. {
  127.     In a class derived from TOleObject, in the implementation of each method corresponding
  128.   to an OLE method to be invoked, call SetOleMethodArg once for each argument to be passed.
  129.     The order in which these calls are made will specify the order in which the arguments are
  130.   to be passed to the OLE method by the CallOleFunction or CallOleProc methods.
  131.  
  132.   ***NOTE***: These calls must be in REVERSE ORDER of the actual argument order!!(I.e.,R->L!)
  133.  
  134.     The sParamType parameter should be one of the following : (case is not significant)
  135.         'Boolean' | 'Integer' | 'Longint' | 'Word' | 'Byte' | 'Char' | 'Single ' | 'Double' |
  136.         'PChar' | 'PInterface' | 'Pointer' | 'ODate' | 'OCurrency' | 'VariantRef'
  137.         *Note: 'PInterface' refers to the pIDisp type defined in the OLETypes unit.
  138.                 and is used to access "nested" OLE objects.
  139.                'ODate' and 'OCurrency' refer to OLE date and currency types (see OLETYPES.PAS).
  140.                'VariantRef' refers to the OLE VARIANT type and can only be passed by reference.
  141.    Optionally, these may be prefixed by the symbol '&' to indicate that the argument is to
  142.   be passed by reference, analogous to a var parameter in Pascal.  Note, however, that
  143.   PChar itself passes null-terminated strings by reference.
  144. }
  145. procedure TOleObject.SetOleMethodArg(sParamType : String; var ActualParam);
  146.  
  147. {
  148.     In a class derived from TOleObject, in the implementation of each method corresponding
  149.   to an OLE method to be invoked, a call to CallOleFunction causes the OLE automation object
  150.   to execute the desired method with parameters determined by the preceding sequence of
  151.   calls to SetOleMethodArg.
  152.     The return types are the same as those specified for SetOleMethodArg,
  153.   except that they may be preceded by a ^ symbol to indicate that the return value
  154.   is a pointer to the specified type.  The actual return value is placed in the
  155.   RetVal argument.
  156.     To call methods that don't return a value, use CallOleProc instead. }
  157. }
  158. procedure TOleObject.CallOleFunction(sMethodName : String; sReturnType : String; var RetVal);
  159.  
  160. {
  161.     Like CallOleFunction, but without any return type.
  162. }
  163. procedure TOleObject.CallOleProc(sMethodName : String);
  164.  
  165. {
  166.     In a class derived from TOleObject, in the implementation of each method corresponding
  167.   to an OLE property to be set, call SetOleProperty once with the property's name,
  168.   type and value.
  169.  
  170.     The sPropertyType parameter should be one of the following : (case is not significant)
  171.         'Boolean' | 'Integer' | 'Longint' | 'Word' | 'Byte' | 'Char' | 'Single ' | 'Double' |
  172.         'PChar' | 'PInterface' | 'Pointer' | 'ODate' | 'OCurrency' | 'VariantRef'
  173.         *Note: 'PInterface' refers to the pIDisp type defined in the OLETypes unit.
  174.                 and is used to access "nested" OLE objects.
  175.                'ODate' and 'OCurrency' refer to OLE date and currency types (see OLETYPES.PAS).
  176.                'VariantRef' refers to the OLE VARIANT type and can only be passed by reference.
  177.     Optionally, these may be prefixed by the symbol '&' to indicate that
  178.   the property value is to be passed by reference, analogous to a var parameter in Pascal.
  179.   This will normally be used only when passing a reference to an OLE object.
  180. }
  181. procedure TOleObject.SetOleProperty(sPropertyName : String;
  182.                         sPropertyType : String; var PropVal);
  183.  
  184. {
  185.     In a class derived from TOleObject, in the implementation of each method corresponding
  186.   to an OLE property to be retrieved, call GetOleProperty once with the property's name
  187.   and type.
  188.  
  189.     The sPropertyType parameter should be one of the following : (case is not significant)
  190.         'Boolean' | 'Integer' | 'Longint' | 'Word' | 'Byte' | 'Char' | 'Single ' | 'Double' |
  191.         'PChar' | 'PInterface' | 'Pointer' | 'ODate' | 'OCurrency' | 'VariantRef'
  192.         *Note: 'PInterface' refers to the pIDisp type defined in the OLETypes unit.
  193.                 and is used to access "nested" OLE objects.
  194.                'ODate' and 'OCurrency' refer to OLE date and currency types (see OLETYPES.PAS).
  195.                'VariantRef' refers to the OLE VARIANT type and can only be retrieved via
  196.                a pointer.
  197.     Optionally, these (except for VariantRef) may be prefixed by the symbol '&' to indicate
  198.     that a pointer to a pointer to the property value is to be retrieved, rather than
  199.     simply a pointer to the value.
  200. }
  201. procedure TOleObject.GetOleProperty(sPropertyName : String;
  202.                         sPropertyType : String; var RetVal);
  203.  
  204. implementation
  205.